<template>
  <div class="AdendDialog">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="22">
          <el-form-item label="角色名称" prop="roleName">
            <el-input v-model="ruleForm.roleName" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="角色别名">
            <el-input v-model="ruleForm.alias" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="备注">
            <el-input v-model="ruleForm.remark" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props:['row'],
    data() {
      return {
        ruleForm: {
          roleId:'',
          roleName: '',
          alias: '',
          remark: '',
          menuIdList:'',
        },
        rules: {
          roleName: [{
            required: true,
            message: '请输入角色名称',
            trigger: 'blur'
          }],
        }
      }
    },
    created: function() {
      this.ruleForm = {
        roleId: this.row.roleId,
        roleName: this.row.roleName,
        alias: this.row.alias,
        remark: this.row.remark,
        menuIdList: this.row.menuIdList,
      }
    },
    methods: {
      // 表单提交
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let params = this.ruleForm;
            this.$server.updateSysRole(params).then(res => {
              this.$message({
                type: "success",
                message: "修改成功!"
              });
              // 关闭弹框
              this.$emit('chang');
            })
          } else {
            // console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$emit('chang');
      },
    }
  }
</script>
<style lang="scss" scoped>
  .AdendDialog {}
</style>
